﻿using CRM.Quartz.Common;
using CRM.Utility;
using Quartz;
using System;
using System.Threading.Tasks;

namespace CRM.Quartz.Jobs
{
    [DisallowConcurrentExecution]
    public class CallEndMessageJob : IJob
    {
        public Task Execute(IJobExecutionContext context)
        {
            //模板+公司ID获取信息
            string message = ConfigHelper.GetAppSettingValue("MessageTpl");
            if (string.IsNullOrEmpty(message))
                return Task.FromResult(true);

            string mobile = "17326926291,18201032670";
            //string.IsNullOrEmpty(clue.HisMobile) ? clue.Mobile : clue.HisMobile;
            try
            {
                SMSClient client = new SMSClient();
                //var rt = client.SendShortMessageAsync(new SmsModel()
                //{
                //    ChannelId = 1,
                //    Content = message,
                //    Mobile = mobile,
                //    PlatformId = 10010
                //    //OpUserId = call.CompanyID,
                //    //OpUserName = call.CompanyID.ToString()
                //}).Result;
                var rt = client.SendServiceShortMessageAsync(new SmsServiceModel()
                {
                    Content = message,
                    Mobile = mobile,
                    PlatformId = 10010
                }).Result;
                if (rt.Status != 0)
                {
                    //_serviceLog.Insert(new ErrorLog()
                    //{
                    //    CreatedDate = DateTime.Now,
                    //    ErrorMessage = rt.Message,
                    //    Moble = mobile,
                    //    PostData = Newtonsoft.Json.JsonConvert.SerializeObject(call),
                    //    RequestUrl = "CRM.Op.Controllers.SendMessage",
                    //    Platform = 10010
                    //});
                }
            }
            catch (Exception ex)
            {
                //_serviceLog.Insert(new ErrorLog()
                //{
                //    CreatedDate = DateTime.Now,
                //    ErrorMessage = ex.Message,
                //    ErrorSource = ex.Source,
                //    ErrorTrace = ex.Source,
                //    Moble = mobile,
                //    PostData = Newtonsoft.Json.JsonConvert.SerializeObject(call),
                //    RequestUrl = "CRM.Op.Controllers.SendMessage",
                //    Platform = 10010
                //});
            }
            return Task.FromResult(true);
        }
    }
}
